library(jtools)
library(plyr)
library(readxl)
lagpad   = function(x, k) {
if (!is.vector(x))
stop('x must be a vector')
if (!is.numeric(x))
stop('x must be numeric')
if (!is.numeric(k))
stop('k must be numeric')
if (1 != length(k))
stop('k must be a single number')
c(rep(NA, k), x)[1 : length(x)]
}
##### MSC DATA #############
data    = read_excel("msc_data.xlsx", sheet = "Export")
data$f1            = data$MICH_mean
data$fc_err        = data$pi_realz - data$f1
data$fl            = lagpad(data$pi_realz,4)
data$dloil         = data$dlwti
data$fc_rev        = data$f1-lagpad(data$f1,1)
data               = subset(data, select = c(year,quarter,qdate,f1,fc_err,fl,dloil,fc_rev))
##### save #######
save(data, file = "us_msc_cpi.rda")
# LIV DATA Clean AVERAGE LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)
lagpad   = function(x, k) {
if (!is.vector(x))
stop('x must be a vector')
if (!is.numeric(x))
stop('x must be numeric')
if (!is.numeric(k))
stop('k must be numeric')
if (1 != length(k))
stop('k must be a single number')
c(rep(NA, k), x)[1 : length(x)]
}
##### lIV DATA GDP #############
data    = read_excel("liv_data_avr.xlsx")
data$fc_err        = data$fc_erry
data$fc_rev        = data$fc_revy
data$fl            = data$fly
data$f1            = data$f1y
data$f1r           = data$f1ry
data$f2r           = data$f2ry
data               = subset(data, select = c(qdate, y, fc_err,fl,fc_rev,f1,f1r,f2r))
save(data, file = "us_liv_rgdp_avr.rda")
clear()
##### LIV DATA CPI #############
data    = read_excel("liv_data_avr.xlsx")
data$fc_err        = data$fc_errpi
data$fc_rev        = data$fc_revpi
data$fl            = data$flpi
data$f1            = data$f1pi
data$f1r           = data$f1rpi
data$f2r           = data$f2rpi
data               = subset(data, select = c(qdate, y, fc_err,fl,fc_rev,f1,f1r,f2r))
save(data, file = "us_liv_cpi_avr.rda")
clear()
# EA SPF DATA Clean AVERAGE LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)
lagpad   = function(x, k) {
if (!is.vector(x))
stop('x must be a vector')
if (!is.numeric(x))
stop('x must be numeric')
if (!is.numeric(k))
stop('k must be numeric')
if (1 != length(k))
stop('k must be a single number')
c(rep(NA, k), x)[1 : length(x)]
}
##### EA DATA GDP #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")
data$fc_err        = data$fey
data$fc_rev        = data$fry
data$fl            = data$fly
data               = subset(data, select = c(year,quarter,qdate, fc_err,fl,fc_rev))
save(data, file = "ea_spf_rgdp_avr.rda")
clear()
##### EA DATA CPI #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")
data$fc_err        = data$fepi
data$fc_rev        = data$frpi
data$fl            = data$flpi
data               = subset(data, select = c(year,quarter,qdate, fc_err,fl,fc_rev))
save(data, file = "ea_spf_cpi_avr.rda")
clear()
### MASTER .R FILE:
# RUNS ALL THE .R OUTPUT PROGRAMS
# SECTION 2 & ONLINE APPENDIX C
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
source("all_tables_output_ind.R")
source(file = "figure_1_and_2.R")
### MASTER .R FILE:
# RUNS ALL THE .R OUTPUT PROGRAMS
# SECTION 2 & ONLINE APPENDIX C
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
tmp = paste0(WD,"/all_tables_output_ind.R","", collapse = NULL)
source("tmp")
tmp =
sdall_tables_output_ind.R
tmp
source(file="tmp")
# EA SPF DATA Clean AVERAGE LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)
lagpad   = function(x, k) {
if (!is.vector(x))
stop('x must be a vector')
if (!is.numeric(x))
stop('x must be numeric')
if (!is.numeric(k))
stop('k must be numeric')
if (1 != length(k))
stop('k must be a single number')
c(rep(NA, k), x)[1 : length(x)]
}
##### EA DATA GDP #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")
data$fc_err        = data$fey
data$fc_rev        = data$fry
data$fl            = data$fly
data               = subset(data, select = c(year,quarter,qdate, fc_err,fl,fc_rev))
save(data, file = "ea_spf_rgdp_avr.rda")
clear()
##### EA DATA CPI #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")
data$fc_err        = data$fepi
data$fc_rev        = data$frpi
data$fl            = data$flpi
data               = subset(data, select = c(year,quarter,qdate, fc_err,fl,fc_rev))
save(data, file = "ea_spf_cpi_avr.rda")
clear()
# LIV DATA Clean AVERAGE LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)
lagpad   = function(x, k) {
if (!is.vector(x))
stop('x must be a vector')
if (!is.numeric(x))
stop('x must be numeric')
if (!is.numeric(k))
stop('k must be numeric')
if (1 != length(k))
stop('k must be a single number')
c(rep(NA, k), x)[1 : length(x)]
}
##### lIV DATA GDP #############
data    = read_excel("liv_data_avr.xlsx")
data$fc_err        = data$fc_erry
data$fc_rev        = data$fc_revy
data$fl            = data$fly
data$f1            = data$f1y
data$f1r           = data$f1ry
data$f2r           = data$f2ry
data               = subset(data, select = c(qdate, y, fc_err,fl,fc_rev,f1,f1r,f2r))
save(data, file = "us_liv_rgdp_avr.rda")
clear()
##### LIV DATA CPI #############
data    = read_excel("liv_data_avr.xlsx")
data$fc_err        = data$fc_errpi
data$fc_rev        = data$fc_revpi
data$fl            = data$flpi
data$f1            = data$f1pi
data$f1r           = data$f1rpi
data$f2r           = data$f2rpi
data               = subset(data, select = c(qdate, y, fc_err,fl,fc_rev,f1,f1r,f2r))
save(data, file = "us_liv_cpi_avr.rda")
clear()
# MSC DATA Clean
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)
lagpad   = function(x, k) {
if (!is.vector(x))
stop('x must be a vector')
if (!is.numeric(x))
stop('x must be numeric')
if (!is.numeric(k))
stop('k must be numeric')
if (1 != length(k))
stop('k must be a single number')
c(rep(NA, k), x)[1 : length(x)]
}
##### MSC DATA #############
data    = read_excel("msc_data.xlsx", sheet = "Export")
data$f1            = data$MICH_mean
data$fc_err        = data$pi_realz - data$f1
data$fl            = lagpad(data$pi_realz,4)
data$dloil         = data$dlwti
data$fc_rev        = data$f1-lagpad(data$f1,1)
data               = subset(data, select = c(year,quarter,qdate,f1,fc_err,fl,dloil,fc_rev))
##### save #######
save(data, file = "us_msc_cpi.rda")
# EA SPF DATA Clean AVERAGE LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)
lagpad   = function(x, k) {
if (!is.vector(x))
stop('x must be a vector')
if (!is.numeric(x))
stop('x must be numeric')
if (!is.numeric(k))
stop('k must be numeric')
if (1 != length(k))
stop('k must be a single number')
c(rep(NA, k), x)[1 : length(x)]
}
##### EA DATA GDP #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")
data$fc_err        = data$fey
data$fc_rev        = data$fry
data               = subset(data, select = c(year,quarter,qdate, fc_err,fc_rev))
data               = data[data$year>="2000",]
save(data, file = "ea_spf_rgdp_avr.rda")
clear()
##### EA DATA CPI #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")
data$fc_err        = data$fepi
data$fc_rev        = data$frpi
data$fl            = data$flpi
data               = subset(data, select = c(year,quarter,qdate, fc_err,fl,fc_rev))
data               = data[data$year>="2000",]
save(data, file = "ea_spf_cpi_avr.rda")
clear()
# SPF OUTPUT TABLES INDIVIDUAL LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
indata0      = paste0(WD,"/_data/_individual_data/_spfrawdata/","", collapse = NULL)
indata1      = paste0(WD,"/_data/_average_data/_spfrawdata/","", collapse = NULL)
indata2      = paste0(WD,"/_data/_individual_data/_otherrawdata/","", collapse = NULL)
indata3      = paste0(WD,"/_data/_average_data/_otherrawdata/","", collapse = NULL)
library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(dplyr)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(ggplot2)
##### main text data  #######
out_nvar        = 8
load(paste(indata1,"us_spf_pgdp_avr.Rda",sep=""))
data_avr        = data
data_avr        = data[data_avr$qdate>=1970.00,]
data_avr        = data[data_avr$qdate<=2020.00,]
load(paste(indata0,"us_spf_pgdp_ind.Rda",sep=""))
data$ID         = data$id
data            = data[data$qdate>=1970.00,]
data            = data[data$qdate<=2020.00,]
data            = ddply(data,.(qdate),transform, cons = mean(f2,na.rm = TRUE))
######## Table 1 ############
ls_out_avr       = lm(fc_err ~ fc_rev, data=data_avr)
robust_out_avr   = sqrt(diag(vcovHC(ls_out_avr, type = "HC1")))
plm_out_rev      = plm(fc_err ~ fc_rev, data=data,index=c("ID", "qdate"), model="within")
double_out_rev   = sqrt(diag(vcovDC(plm_out_rev, type = "HC1")))
plm_out_cons     = plm(fc_err ~ cons, data=data,index=c("ID", "qdate"), model="within")
double_out_cons  = sqrt(diag(vcovDC(plm_out_cons, type = "HC1")))
plm_out_comb     = plm(fc_err ~ fc_rev + cons, data=data,index=c("ID", "qdate"), model="within")
double_out_comb  = sqrt(diag(vcovDC(plm_out_comb, type = "HC1")))
stderror = list(robust_out_avr, double_out_rev, double_out_cons, double_out_comb)
stargazer(ls_out_avr, plm_out_rev, plm_out_cons, plm_out_comb,
type = "text",
se = stderror,
out="_tables/table_1.txt")
######## Table 2 ############
out_beta_avr  = rep(NA, out_nvar)
out_se_avr    = rep(NA, out_nvar)
out_beta_rev  = rep(NA, out_nvar)
out_se_rev    = rep(NA, out_nvar)
out_beta_cons = rep(NA, out_nvar)
out_se_cons   = rep(NA, out_nvar)
iter        = 0
# individual results
data_series =  c('us_spf_pgdp_ind.rda','us_spf_cpi_ind.rda','us_spf_rgdp_ind.Rda','us_spf_pgdp_ind.rda','us_spf_cpi_ind.rda','us_spf_rgdp_ind.Rda', 'ea_spf_cpi_ind.rda', 'ea_spf_rgdp_ind.rda')
for ( i in data_series){
iter = iter+1
if (iter<=6){
load(paste(indata0,i,sep=""))
} else if (iter>=7 & iter<=8) {
load(paste(indata2,i,sep=""))
}
data$ID       = data$id
data          = ddply(data,.(qdate),transform, cons = mean(f2,na.rm = TRUE))
if (iter<=3){
data            = data[data$qdate>=1970,]
data            = data[data$qdate<= 2020,]
} else if (iter>=4 & iter<=6) {
data            = data[data$qdate>=1992,]
data            = data[data$qdate<= 2020,]
} else if (iter>=7 & iter<=8) {
data            = data[data$qdate>=2000,]
data            = data[data$qdate<= 2020,]
}
plm_all_rev     = plm(fc_err ~ fc_rev, data=data,index=c("ID", "qdate"), model="within")
beta          = coefficients(plm_all_rev)
std_error     = sqrt(diag(vcovDC(plm_all_rev, type = "HC1")))
out_beta_rev[iter]   = as.numeric(beta[1])
out_se_rev[iter]     = as.numeric(std_error[1])
plm_all_cons   = plm(fc_err ~ cons, data=data,index=c("ID", "qdate"), model="within")
beta          = coefficients(plm_all_cons)
std_error     = sqrt(diag(vcovDC(plm_all_cons, type = "HC1")))
out_beta_cons[iter]   = as.numeric(beta[1])
out_se_cons[iter]     = as.numeric(std_error[1])
}
# average results
iter = 0
data_series =  c('us_spf_pgdp_avr.rda','us_spf_cpi_avr.rda','us_spf_rgdp_avr.Rda','us_spf_pgdp_avr.rda','us_spf_cpi_avr.rda','us_spf_rgdp_avr.Rda')
for ( i in data_series){
load(paste(indata1,i,sep=""))
iter = iter+1
if (iter<4){
data    = data[data$qdate>=1970,]
data    = data[data$qdate<= 2020,]
}
else{
data    = data[data$qdate>=1992,]
data    = data[data$qdate<= 2020,]
}
lm_all_rev      = lm(fc_err ~ fc_rev, data=data)
beta          = coefficients(lm_all_rev)
std_error     = sqrt(diag(vcovHC(lm_all_rev, type = "HC1")))
out_beta_avr[iter]   = as.numeric(beta[2])
out_se_avr[iter]     = as.numeric(std_error[2])
}
all_spf =  data.frame(out_beta_avr, out_se_avr, out_beta_rev,out_se_rev, out_beta_cons,out_se_cons)
rownames(all_spf) = c("US SPF Deflator", "US SPF Inflation","US SPF Output", "US SPF Defl P92", "US SPF Infl P92","US SPF Out P92")
colnames(all_spf) = c("beta avr", "se avr", "beta rev", "se rev", "beta cons", "se cons")
write.table(format(all_spf,digits=3), file = "_tables/table_2.txt", sep = "\t")
# EA SPF DATA Clean AVERAGE LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)
lagpad   = function(x, k) {
if (!is.vector(x))
stop('x must be a vector')
if (!is.numeric(x))
stop('x must be numeric')
if (!is.numeric(k))
stop('k must be numeric')
if (1 != length(k))
stop('k must be a single number')
c(rep(NA, k), x)[1 : length(x)]
}
##### EA DATA GDP #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")
data$fc_err        = data$fey
data$fc_rev        = data$fry
data               = subset(data, select = c(year,quarter,qdate, fc_err,fc_rev))
data               = data[data$year>="2000",]
save(data, file = "ea_spf_rgdp_avr.rda")
clear()
##### EA DATA CPI #############
data    = read_excel("ea_data_avr.xlsx", sheet = "Export")
data$fc_err        = data$fepi
data$fc_rev        = data$frpi
data$fl            = data$flpi
data               = subset(data, select = c(year,quarter,qdate, fc_err,fl,fc_rev))
data               = data[data$year>="2000",]
save(data, file = "ea_spf_cpi_avr.rda")
clear()
# LIV DATA Clean AVERAGE LEVEL
rm(list=ls())
(WD <- getwd())
if (!is.null(WD)) setwd(WD)
library(haven)
library(AER)
library(sandwich)
library(lmtest)
library(pracma)
library(stargazer)
library(plm)
library(pracma)
library(DataCombine)
library(jtools)
library(plyr)
library(readxl)
lagpad   = function(x, k) {
if (!is.vector(x))
stop('x must be a vector')
if (!is.numeric(x))
stop('x must be numeric')
if (!is.numeric(k))
stop('k must be numeric')
if (1 != length(k))
stop('k must be a single number')
c(rep(NA, k), x)[1 : length(x)]
}
##### lIV DATA GDP #############
data    = read_excel("liv_data_avr.xlsx")
data$fc_err        = data$fc_erry
data$fc_rev        = data$fc_revy
data$fl            = data$fly
data$f1            = data$f1y
data$f1r           = data$f1ry
data$f2r           = data$f2ry
data               = subset(data, select = c(qdate, y, fc_err,fl,fc_rev,f1,f1r,f2r))
save(data, file = "us_liv_rgdp_avr.rda")
clear()
##### LIV DATA CPI #############
data    = read_excel("liv_data_avr.xlsx")
data$fc_err        = data$fc_errpi
data$fc_rev        = data$fc_revpi
data$fl            = data$flpi
data$f1            = data$f1pi
data$f1r           = data$f1rpi
data$f2r           = data$f2rpi
data               = subset(data, select = c(qdate, y, fc_err,fl,fc_rev,f1,f1r,f2r))
save(data, file = "us_liv_cpi_avr.rda")
clear()
